﻿using System;
using System.Collections;
using System.Configuration;
using System.Collections.Specialized;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;
using System.Drawing;
using IronOne.SalesOne.BusinessObjects;


namespace IronOne.SalesOne.SalesOneWeb.Messaging
{
    public partial class UpadateMessage : SOSecurityPage
    {

        Facade.StructureFacade structureFacade = new Facade.StructureFacade();
        Facade.MessageFacade messageFacade = new Facade.MessageFacade();

        private static string userName;
        private static string userId;
        private static int messageId;
        private static UserInformation info;
        private static int userType;
        private static int groupId;
        private static DateTime created;
        private static Guid createdBy;

        private static List<Branch> lstBranches;
        private static List<SalesOneUnit> lstUnits;
        private static List<string> lstSocodes;

        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                SetCredentials(ValidateUserCredentials(Request.Url.LocalPath));

                if (!IsPostBack)
                {

                    if (Page.Request.Params["MessageId"] != null)
                    {
                        int intMessageId = Convert.ToInt32(Page.Request.Params["MessageId"].ToString());

                        Message message = messageFacade.GetMessage(intMessageId);
                        created = message.Created;
                        createdBy = message.CreatedBy;
                        /*Get The current User*/
                        MembershipUser membershipUser = Membership.GetUser(HttpContext.Current.User.Identity.Name);
                        userName = membershipUser.UserName;
                        User user = structureFacade.GetUser(userName);
                        userId = user.UserId.ToString();


                        info = structureFacade.GetUserInformation(User.Identity.Name);
                        userType = info.UserType;

                        if (userType != 1)
                            groupId = (int)info.GroupId;
                        else
                            groupId = 0;


                        ////SetDataSourceToFrom(structureFacade.GetUserTypesForUser("UserTypeId ASC", userName));
                        //SetDataSourceToFrom(structureFacade.GetUserTypes("UserTypeId ASC"));
                        //string ss = (structureFacade.GetUserTypeForUser(userName).UserTypeId.ToString());
                        ////ddlFrom.SelectedValue = structureFacade.GetUserTypeForUser(userName).UserTypeId.ToString();
                        //ddlFrom.SelectedIndex= structureFacade.GetUserTypeForUser(userName).UserTypeId;

                        ///*
                        //PopulateValuesForUserType();
                        //*/

                        ///*Sajith Code using sp*/
                        //bool flag = false;

                        //chkBroadcast.Enabled = false;


                        //if (userType == 4)
                        //{
                        //    if (user.SoCode != null)
                        //    {
                        //        lstSocodes = new List<string>();
                        //        lstSocodes.Add(user.SoCode);
                        //        SetDataSourceToSoCode(lstSocodes);
                        //        ddlSOCode.SelectedIndex = ddlSOCode.Items.Count - 1;
                        //        ddlSOCode.Enabled = false;
                        //    }
                        //    else
                        //        SetDataSourceToSoCode(structureFacade.GetSOsInUnit(user.NodeId));
                        //    flag = true;
                        //}

                        //if (flag == true)
                        //{
                        //    //ListItem item =new ListItem();
                        //    //item.Text=info.UnitName;
                        //    //item.Value=Convert.ToInt32(info.UnitId).ToString();
                        //    //ddlUnit.Items.Add(item);
                        //    lstUnits = new List<SalesOneUnit>();
                        //    lstUnits.Add(structureFacade.GetUnit(Convert.ToInt32(info.UnitId)));
                        //    SetDataSourceToUnits(lstUnits);
                        //    ddlUnit.SelectedIndex = ddlUnit.Items.Count - 1;
                        //    ddlUnit.Enabled = false;
                        //}
                        //else if (userType == 3)
                        //{
                        //    lstUnits = structureFacade.GetUnitsForBranch(Convert.ToInt32(user.NodeId));
                        //    SetDataSourceToUnits(lstUnits);
                        //    flag = true;
                        //}

                        //if (flag == true)
                        //{
                        //    lstBranches = new List<Branch>();
                        //    lstBranches.Add(structureFacade.GetBranch(Convert.ToInt32(info.BranchId)));
                        //    SetDataSourceToBranches(lstBranches);
                        //    ddlBranch.SelectedIndex = ddlBranch.Items.Count - 1;
                        //    ddlSOCode.SelectedIndex = 0;
                        //    ddlBranch.Enabled = false;
                        //}
                        //else if (userType == 2)
                        //{
                        //    lstBranches = structureFacade.GetBranchesForGroup(Convert.ToInt32(groupId));
                        //    SetDataSourceToBranches(lstBranches);
                        //    flag = true;
                        //}

                        //if (userType == 1)
                        //{
                        //    chkBroadcast.Enabled = true;
                        //    lstBranches = structureFacade.GetBranches("BranchName ASC");
                        //    SetDataSourceToBranches(lstBranches);
                        //}


                        ////SetDataSourceToFrom(structureFacade.GetUserTypesForUser("UserTypeId ASC", userName));
                        InitiateMessageValues(message);
                        SetControlsForUser(HttpContext.Current.User.Identity.Name);
                    }
                }
                ddlFrom.Enabled = false;

                //lblError.ForeColor = Color.Black;
                //lblError.Text = "";
            }
            catch { MassageSummery("IIS514"); }
        }

        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            try
            {
                if (ddlFrom.SelectedIndex > 0)
                {
                    bool isValid = false;

                    ManageMessages updateMessage = new ManageMessages();
                    updateMessage.MessageId = Convert.ToInt32(Page.Request.Params["MessageId"].ToString());
                    updateMessage.UserId = structureFacade.GetUser(userName).UserId;
                    updateMessage.Body = txtMessage.Text;
                    updateMessage.GroupId = Convert.ToInt32(info.GroupId);
                    updateMessage.FromUserTypeId = Convert.ToInt32(ddlFrom.SelectedValue);
                    updateMessage.Broadcasted = chkBroadcast.Checked;
                    updateMessage.Created = created;
                    updateMessage.CreatedBy = createdBy;

                    if (updateMessage.Broadcasted)
                    {
                        isValid = true;
                    }
                    else
                    {
                        if (ddlBranch.SelectedIndex > 0)
                        {
                            if (ddlBranch.SelectedIndex == 1)
                                updateMessage.Branches = lstBranches;
                            else
                            {
                                updateMessage.BranchId = Convert.ToInt32(ddlBranch.SelectedValue);
                                List<Branch> lst = new List<Branch>();
                                lst.Add(lstBranches.Find(GetBranch));
                                updateMessage.Branches = lst;
                            }

                            isValid = true;

                        }
                        if (ddlUnit.SelectedIndex > 0)
                        {
                            if (ddlUnit.SelectedIndex == 1)
                                updateMessage.Units = lstUnits;
                            else
                            {
                                List<SalesOneUnit> lst = new List<SalesOneUnit>();
                                lst.Add(lstUnits.Find(GetUnit));
                                updateMessage.Units = lst;
                            }

                            isValid = true;

                        }
                        if (ddlSOCode.SelectedIndex > 0)
                        {
                            if (ddlSOCode.SelectedIndex == 1)
                                updateMessage.SOCodes = lstSocodes;
                            else
                            {
                                List<string> lst = new List<string>();
                                lst.Add(lstSocodes.Find(GetSOCode));
                                updateMessage.SOCodes = lst;
                            }

                            isValid = true;
                        }
                    }


                    if (isValid)
                    {
                        messageFacade.UpdateMessage(updateMessage);
                        Response.Redirect("~/Messaging/SearchMessages.aspx?MessageId=" + updateMessage.MessageId.ToString() + "&UserType=" +userType.ToString());
                    }
                    else
                    {
                        MassageSummery("IIS505");
                    }
                }
                else
                {
                    MassageSummery("IIS505");
                }
            }
            catch
            {
                MassageSummery("IIS502");
            }
        }

        public void SetDataSourceToBranches(List<Branch> branches)
        {

            try
            {
                ddlBranch.SelectedIndex = 0;
            }
            catch { ddlBranch.SelectedIndex = -1; }
            ddlBranch.Items.Clear();

            if (branches.Count > 0)
            {
                ddlBranch.DataSource = branches;
                ddlBranch.DataTextField = "BranchName";
                ddlBranch.DataValueField = "BranchID";
                ddlBranch.DataBind();
            }

            InsertDDLItems(ddlBranch, "Select...", 0);
            InsertDDLItems(ddlBranch, "All", 1);
        }

        public void SetDataSourceToUnits(List<SalesOneUnit> units)
        {
            try
            {
                ddlUnit.SelectedIndex = 0;
            }
            catch { ddlUnit.SelectedIndex = -1; }
            ddlUnit.ClearSelection();
            ddlUnit.Items.Clear();
            
            if (units.Count > 0)
            {
                ddlUnit.DataSource = units;
                ddlUnit.DataTextField = "name";
                ddlUnit.DataValueField = "unitId";
                ddlUnit.DataBind();
            }

            InsertDDLItems(ddlUnit, "Select...", 0);
            InsertDDLItems(ddlUnit, "All", 1);
        }

        public void SetDataSourceToSoCode(List<string> users)
        {
            try
            {
                ddlSOCode.SelectedIndex = 0;
            }
            catch { ddlSOCode.SelectedIndex = -1; }
            ddlSOCode.Items.Clear();

            if (users.Count > 0)
            {
                ddlSOCode.DataSource = users;
                ddlSOCode.DataBind();
            }

            InsertDDLItems(ddlSOCode, "Select...", 0);
            InsertDDLItems(ddlSOCode, "All", 1);
        }


        public void SetDataSourceToSoCode(List<User> users)
        {
            ddlSOCode.DataSource = users;
            ddlSOCode.DataTextField = "Name";
            ddlSOCode.DataValueField = "UserId";
            ddlSOCode.DataBind();

            InsertDDLItems(ddlSOCode, "Select...", 0);
            InsertDDLItems(ddlSOCode, "All", 1);
        }

        public void SetDataSourceToFrom(List<UserType> userTypes)
        {
            try
            {
                ddlFrom.SelectedIndex = 0;
            }
            catch { ddlFrom.SelectedIndex = -1; }
            ddlFrom.Items.Clear();

            if (userTypes.Count > 0)
            {
                ddlFrom.DataSource = userTypes;
                ddlFrom.DataTextField = "UserTypeName";
                ddlFrom.DataValueField = "UserTypeId";
                ddlFrom.DataBind();
            }

            InsertDDLItems(ddlFrom, "Select...", 0);
            //InsertDDLItems(ddlFrom, "All", 1);
        }

        public void InsertDDLItems(DropDownList ddl, string Text, int Position)
        {
            ListItem item = new ListItem(Text, Text);
            ddl.Items.Insert(Position, Text);
        }

        protected void chkBroadcast_CheckedChanged(object sender, EventArgs e)
        {
            try
            {
                DisableControlsForBroadcasting();
            }
            catch { MassageSummery("IIS514"); }
        }

        public void DisableControlsForBroadcasting()
        {
            if (chkBroadcast.Checked)
            {
                EnableControls(false);
            }
            else
            {
                EnableControls(true);
            }
        }

        protected void ddlUnit_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                SetValuesForUnitValue();
                DisableControlsForUserType(userType);
            }
            catch { MassageSummery("IIS514"); }
        }

        protected void ddlFrom_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                SetValuesForFromValue();
                DisableControlsForUserType(userType);
            }
            catch { MassageSummery("IIS514"); }
        }

        public void DisableControlsForHQ()
        {
            chkBroadcast.Enabled = false;
            chkBroadcast.Checked = false;
            DisableControlsForBroadcasting();
        }

        public void EnableControls(bool enabled)
        {
            ddlBranch.Enabled = enabled;
            ddlUnit.Enabled = enabled;
            ddlSOCode.Enabled = enabled;
        }

        private bool GetBranch(Branch branch)
        {
            if (branch.BranchId == Convert.ToInt32(ddlBranch.SelectedValue))
                return true;
            else
                return false;

        }

        private bool GetUnit(SalesOneUnit unit)
        {
            if (unit.UnitId == Convert.ToInt32(ddlUnit.SelectedValue))
                return true;
            else
                return false;
        }

        private bool GetSOCode(string soCode)
        {
            if (soCode.Equals(ddlSOCode.SelectedItem.Text))
                return true;
            else
                return false;

        }

        protected void ddlBranch_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                SetValuesForBranchValue();
                DisableControlsForUserType(userType);
            }
            catch { MassageSummery("IIS514"); }
        }

        //private void IniateValues(Message message)
        //{
        //    txtMessage.Text = message.MessageBody;

        //    //ddlFrom.SelectedValue = message.MessageFromUserTypeID.ToString();
        //    ddlFrom.SelectedValue = (structureFacade.GetUserTypeForUser(userName).UserTypeId.ToString());
        //    SetValuesForFromValue();

        //    chkBroadcast.Checked = (message.UserTypeId==1);

        //    if (chkBroadcast.Checked)
        //        DisableControlsForBroadcasting();

        //    if (message.UserTypeId == 2)
        //    {
        //        ddlBranch.SelectedIndex = 1;
        //        SetValuesForBranchValue();
        //    }
        //    else if (message.UserTypeId == 3)
        //    {
        //        ddlBranch.SelectedValue = message.NodeId.ToString();
        //        SetValuesForBranchValue();
        //    }
               
        //    else if (message.UserTypeId == 4)
        //    {
        //        lstUnits = new List<SalesOneUnit>();
        //        lstUnits.Add(structureFacade.GetUnit(message.NodeId));
        //        SetDataSourceToUnits(lstUnits);
        //        ddlUnit.SelectedIndex = ddlUnit.Items.Count - 1;

        //        lstBranches = new List<Branch>();
        //        lstBranches.Add(structureFacade.GetBranchForUnit(message.NodeId));
        //        SetDataSourceToBranches(lstBranches);
        //        ddlBranch.SelectedIndex= ddlBranch.Items.Count - 1; ;
        //        //ddlUnit.SelectedValue = message.NodeId.ToString();
        //        SetValuesForUnitValue();
        //        if (message.SoCodeId == "")
        //            ddlSOCode.SelectedIndex = 0;
        //        else
        //        {
        //            lstSocodes = new List<string>();
        //            lstSocodes.Add(message.SoCodeId);
        //            SetDataSourceToSoCode(lstSocodes);
        //            ddlSOCode.SelectedIndex = ddlSOCode.Items.Count;
        //        }
            
        //    }
        //    else
        //    {
        //        if (message.UserTypeId != 1)
        //        {
        //            lstUnits = new List<SalesOneUnit>();
        //            lstUnits.Add(structureFacade.GetUnit(message.NodeId));
        //            SetDataSourceToUnits(lstUnits);

        //            ddlUnit.SelectedIndex = ddlUnit.Items.Count - 1;

        //            ddlBranch.SelectedValue = structureFacade.GetBranchForUnit(message.NodeId).BranchId.ToString();

        //            ddlSOCode.SelectedValue = message.SoCodeId;
        //        }
        //    }

        //}

        private void SetValuesForFromValue()
        {
            if (ddlFrom.SelectedIndex > 0)
            {
                if (userType == 2)
                {
                    lstBranches = structureFacade.GetBranchesForGroup(groupId);
                    SetDataSourceToBranches(lstBranches);
                    ddlBranch.SelectedIndex = 0;
                }
                else
                {
                    lstBranches = structureFacade.GetBranches("BranchName ASC");
                    SetDataSourceToBranches(lstBranches);
                    ddlBranch.SelectedIndex = 0;
                }
                if (ddlFrom.SelectedItem.Text.Equals("HQ", StringComparison.InvariantCultureIgnoreCase))
                {
                    chkBroadcast.Enabled = true;
                    ClearControls(1);
                    EnableControls(true);
                }
                else
                {
                    DisableControlsForHQ();
                    ClearControls(1);
                    EnableControls(true);
                }
            }
            //if (ddlFrom.SelectedItem.Text.Equals("HQ", StringComparison.InvariantCultureIgnoreCase))
            //{
            //    chkBroadcast.Enabled = true;
            //    lstBranches = structureFacade.GetBranches("BranchName ASC");
            //    SetDataSourceToBranches(lstBranches);
            //    ddlUnit.Items.Clear();
            //    ddlSOCode.Items.Clear();
            //    EnableControls(true);
            //}
            ///*If Group selected populate the branches according to the group*/
            //else if (ddlFrom.SelectedItem.Text.Equals("Group", StringComparison.InvariantCultureIgnoreCase))
            //{
            //    DisableControlsForHQ();
            //    lstBranches = structureFacade.GetBranchesForGroup(Convert.ToInt32(info.GroupId));
            //    SetDataSourceToBranches(lstBranches);
            //    //populate branches
            //    ddlUnit.Items.Clear();
            //    ddlSOCode.Items.Clear();
            //    EnableControls(true);
            //}
            ///*If brnch - populate the branches according to the selected branch */
            //else if (ddlFrom.SelectedItem.Text.Equals("Branch", StringComparison.InvariantCultureIgnoreCase))
            //{
            //    DisableControlsForHQ();
            //    //populate units
            //    lstUnits = structureFacade.GetUnitsForBranch(Convert.ToInt32(info.BranchId));
            //    SetDataSourceToUnits(lstUnits);
            //    ddlSOCode.Items.Clear();
            //    ddlBranch.Enabled = false;
            //}
            ///*If units then -units acoording to the .....*/
            //else if (ddlFrom.SelectedItem.Text.Equals("Unit", StringComparison.InvariantCultureIgnoreCase))
            //{
            //    lstSocodes = structureFacade.GetSOsInUnit(Convert.ToInt32(info.UnitId));
            //    SetDataSourceToSoCode(lstSocodes);
            //    DisableControlsForHQ();
            //    //populate socodes
            //    ddlBranch.Enabled = false;
            //    ddlBranch.Items.Clear();
            //}


        }

        private void SetValuesForBranchValue()
        {
            EnableControls(true);
            if (ddlBranch.SelectedIndex > 1)
            {
                ddlUnit.Items.Clear();
                lstUnits = structureFacade.GetUnitsInBranch(int.Parse(ddlBranch.SelectedValue));
                SetDataSourceToUnits(lstUnits);
                ddlUnit.SelectedIndex = 0;
                
                ddlSOCode.Items.Clear();
            }
            else if (ddlBranch.SelectedIndex == 1)
            {
                ddlUnit.Enabled = false;
                ddlUnit.Items.Clear();
                ddlSOCode.Enabled = false;
                ddlSOCode.Items.Clear();
            }
        }

        private void SetValuesForUnitValue()
        {
            EnableControls(true);
            if (ddlUnit.SelectedIndex > 1)
            {
                ddlSOCode.Items.Clear();
                lstSocodes = structureFacade.GetSOsInUnit(int.Parse(ddlUnit.SelectedValue));
                SetDataSourceToSoCode(lstSocodes);              
            }
            else if (ddlUnit.SelectedIndex == 1)
            {
                ddlSOCode.Enabled = false;
                ddlSOCode.Items.Clear();
            }
        }

        public void SetCredentials(StringCollection credential)
        {
            foreach (string item in credential)
            {
                if(item.ToLower()=="u")                                   
                    btnUpdate.Visible = true;
                     
            }
        }

        public void DisableControlsForUserType(int userType)
        {
            bool flag = false;

            MembershipUser membershipUser = Membership.GetUser(HttpContext.Current.User.Identity.Name);
            userName = membershipUser.UserName;
            User user = structureFacade.GetUser(userName);

            if (userType == 4)
            {
               
            }

            if (flag == true)
            {

                ddlUnit.Enabled = false;
            }
            else if (userType == 3)
            {

                flag = true;
            }

            if (flag == true)
            {

                ddlBranch.Enabled = false;
            }
            else if (userType == 2)
            {

                flag = true;
            }

            if (userType == 1)
            {
                chkBroadcast.Enabled = true;

            }
        }

        protected void btnCancel_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/Messaging/SearchMessages.aspx");
        }

        protected void ddlSOCode_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                DisableControlsForUserType(userType);
            }
            catch { MassageSummery("IIS514"); }
        }

        private void InitiateMessageValues(Message message)
        {
            SetDataSourceToFrom(structureFacade.GetUserTypes("UserTypeId ASC"));
            ddlFrom.SelectedIndex = userType;
            SetValuesForFromValue();//

            txtMessage.Text = message.MessageBody;

            chkBroadcast.Checked = (message.UserTypeId == 1);

            if (chkBroadcast.Checked)
                DisableControlsForBroadcasting();

            if (message.UserTypeId == 2)
            {
                ddlBranch.SelectedIndex = 1;
                SetValuesForBranchValue();
            }
            else if (message.UserTypeId == 3)
            {
                ddlBranch.SelectedValue = message.NodeId.ToString();
                SetValuesForBranchValue();
            }
             else if (message.UserTypeId == 4)
            { 
                ddlBranch.SelectedValue = structureFacade.GetBranchForUnit(message.NodeId).BranchId.ToString();
                SetValuesForBranchValue();

                ddlUnit.SelectedValue = message.NodeId.ToString();                
                SetValuesForUnitValue();

                if (message.SoCodeId == "")
                    ddlSOCode.SelectedIndex = 0;
                else
                {
                    ddlSOCode.SelectedValue = message.SoCodeId;
                }

            }

        }

        private void ClearControls(int status)
        {
            if (status == 0)
            {
                ddlBranch.Items.Clear();
                ddlUnit.Items.Clear();
                ddlSOCode.Items.Clear();
            }
            else if (status == 1)
            {
                ddlUnit.Items.Clear();
                ddlSOCode.Items.Clear();
            }
            else if (status == 2)
            {
                ddlSOCode.Items.Clear();
            }
            else if (status == 3)
            {
                ddlBranch.Items.Clear();
                ddlUnit.Items.Clear();
            }
            else if (status == 4)
            {
                ddlBranch.Items.Clear();
                ddlSOCode.Items.Clear();
            }
        }

        private void SetControlsForUser(string userName)
        {
            User user = structureFacade.GetUser(userName);

            userId = user.UserId.ToString();

            UserInformation info = structureFacade.GetUserInformation(User.Identity.Name);
            userType = info.UserType;

            /*Sajith Code using sp*/
            bool flag = false;


            if (userType == 4)
            {
                //if (user.SoCode != null)
                //{
                //    lstSocodes = new List<string>();
                //    lstSocodes.Add(user.SoCode);
                //    SetDataSourceToSoCode(lstSocodes);
                //    ddlSOCode.SelectedIndex = ddlSOCode.Items.Count - 1;
                //    ddlSOCode.Enabled = false;
                //}
                //else
                //{
                //SetDataSourceToSoCode(structureFacade.GetSOsInUnit(user.NodeId));
                //if (ddlSOCode.SelectedIndex == -1)
                //}
                flag = true;
            }

            if (flag == true)
            {
                lstUnits = new List<SalesOneUnit>();
                lstUnits.Add(structureFacade.GetUnit(Convert.ToInt32(info.UnitId)));
                SetDataSourceToUnits(lstUnits);
                ddlUnit.SelectedIndex = ddlUnit.Items.Count - 1;
                ddlUnit.Enabled = false;
            }
            else if (userType == 3)
            {
                if (IsPostBack)
                {
                    lstUnits = structureFacade.GetUnitsForBranch(Convert.ToInt32(user.NodeId));
                    SetDataSourceToUnits(lstUnits);

                }
                
                ddlBranch.SelectedIndex = ddlBranch.Items.Count - 1;
                flag = true;
            }

            if (flag == true)
            {
                lstBranches = new List<Branch>();
                lstBranches.Add(structureFacade.GetBranch(Convert.ToInt32(info.BranchId)));
                SetDataSourceToBranches(lstBranches);
                ddlBranch.SelectedIndex = ddlBranch.Items.Count - 1;

                ddlBranch.Enabled = false;
            }
            //else if (userType == 2)
            //{
            //    if (status)
            //    {
            //        lstBranches = structureFacade.GetBranchesForGroup(Convert.ToInt32(user.NodeId));
            //        SetDataSourceToBranches(lstBranches);
            //        ddlBranch.SelectedIndex = 0;
            //        flag = true;
            //    }
            //}

            //if (userType == 1)
            //{
            //    if (status)
            //    {
            //        chkBroadcast.Enabled = true;
            //        lstBranches = structureFacade.GetBranches("BranchName ASC");
            //        SetDataSourceToBranches(lstBranches);
            //        ddlBranch.SelectedIndex = 0;
            //    }
            //}

        }

    }
}
